<?php
/**
 * #Celebrate Shieh
 *             ,%%%%%%%%,
 *           ,%%/\%%%%/\%%
 *          ,%%%\c "" J/%%%
 * %.       %%%%/ o  o \%%%
 * `%%.     %%%%    _  |%%%
 *  `%%     `%%%%(__Y__)%%'
 *  //       ;%%%%`\-/%%%'
 * ((       /  `%%%%%%%'
 *  \\    .'          |
 *   \\  /       \  | |
 *    \\/         ) | |
 *     \         /_ | |__
 *     (___________))))))) 攻城湿
 *
 *        _       _
 * __   _(_)_   _(_) __ _ _ __
 * \ \ / / \ \ / / |/ _` |'_ \
 *  \ V /| |\ V /| | (_| | | | |
 *   \_/ |_| \_/ |_|\__,_|_| |_|
 */

namespace App\Services;

use Carbon\Carbon;
use Illuminate\Http\Request;

class SensitiveService
{
    use Service;

    /**
     * 敏感词首页
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
     */
    public function SensitiveIndexService()
    {
        $txt  = config('page.txt');
        $disk = $this->getStorage('public');
        if ( ! $disk->exists($txt) ) $disk->put($txt, '');//不存在就创建文件
        $sensitive[ 'text' ] = $disk->get($txt);//获取内容
        $sensitive[ 'size' ] = maxsize($disk->size($txt));//获取大小
        $sensitive[ 'time' ] = ( new Carbon() )->createFromTimestamp($disk->time($txt))->toDateTimeString();//获取创建时间
        return view('blog.sensitive.index', compact('sensitive'));
    }

    /**
     * 敏感词修改
     *
     * @param Request $request
     *
     * @return \Illuminate\Http\RedirectResponse
     */
    public function SensitiveStoreService( $request )
    {
        $disk = $this->getStorage('public');
        $disk->put(config('page.txt'), $request->input('sensitive'));//写入
        return back()->with('success', $this->getErrorCode()::message(203));
    }
}
